<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%--
- Author(s): 
- Date: 2018-03-29 17:16:38
- Description:
    --%>
    <head>
        <title>
            项目录入
        </title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <script src="<%= request.getContextPath() %>/common/nui/nui.js" type="text/javascript">
        </script>
    </head>
    <body>
        <!-- 标识页面是查看(query)、修改(edit)、新增(add) -->
        <input name="pageType" class="nui-hidden"/>
        <div id="dataform1" style="padding-top:5px;">
            <!-- hidden域 -->
            <input class="nui-hidden" name="zhmyproject.projectId"/>
            <table style="width:100%;height:100%;table-layout:fixed;" class="nui-form-table">
                <tr>
                    <td class="form_label">
                        项目名称:
                    </td>
                    <td colspan="1">
                        <input class="nui-textbox" name="zhmyproject.projectName" required="true" vtype="maxLength:20" />
                    </td>
                    <td class="form_label">
                        项目进度:
                    </td>
                    
                    <td colspan="1">
                        <input class="nui-dictcombobox" dictTypeId="PROJECT_PROGRESS" name="zhmyproject.projectStatus" value="1" required="true" />
                    </td>
                    </tr>
                <tr>
                    <td class="form_label">
                        合约交付时间:
                    </td>
                    <td colspan="1">
                        <input class="nui-datepicker" name="zhmyproject.projectPactTime" required="true"/>
                    </td>
                
                    <td class="form_label">
                        预计交付时间:
                    </td>
                    <td colspan="1">
                        <input class="nui-datepicker" name="zhmyproject.projectExpectTime"/>
                    </td>
                 </tr>
                <tr id="version">
                    <td class="form_label">
                        版本号:
                    </td>
                    <td colspan="3">
                        <input class="nui-textbox" name="versionNumber" vtype="maxLength:50" />
                    </td>
                <style>.mini-checkboxlist-item{
                margin-right:0}</style>
                
                <tr>
                    <td class="form_label">
                        客户名:
                    </td>
                    <td colspan="3">
                    	<input id="lookup2" name="zhmyproject.zhmyCustomer.customerId" class="nui-lookup"
							textField="customerCompanyName" valueField="customerId" popupWidth="auto"
							popup="#gridPanel" grid="#datagrid1" multiSelect="true" style="width:100%" required="true"/>
                    </td>
                </tr>
                <tr>
                    <td class="form_label">
                        项目说明:
                    </td>
                    <td colspan="3">
                        <input class="nui-textarea" name="zhmyproject.projectNote" style="width:100%;" vtype="maxLength:200" />
                    </td>
                </tr>
            </table>
            <div class="nui-toolbar" style="padding:0px;" borderStyle="border:0;">
                <table width="100%">
                    <tr>
                        <td style="text-align:center;" colspan="4">
                            <a class="nui-button" iconCls="icon-save" onclick="onOk()">
                                保存
                            </a>
                            <span style="display:inline-block;width:25px;">
                            </span>
                            <a class="nui-button" iconCls="icon-cancel" onclick="onCancel()">
                                取消
                            </a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <!--  look up start -->
        <div id="gridPanel" class="nui-panel" title="header" iconCls="icon-add" style="width:450px;height:250px;"
		showToolbar="true" showCloseButton="true" showHeader="false" bodyStyle="padding:0"borderStyle="border:0">
			<div property="toolbar" style="padding:5px;padding-left:8px;text-align:center;">
				<div style="float:left;padding-bottom:2px;"> 
					<span>公司名称:</span>
					<input id="keyText" class="nui-textbox" style="width:160px;"
		onenter="onSearchClick"/>
					<a class="nui-button" onclick="onSearchClick">查询</a>
					<a class="nui-button" onclick="onClearClick">清除</a>
				</div>
				<div style="float:right;padding-bottom:2px;">
					<a class="nui-button" onclick="onCloseClick">关闭</a>
				</div>
				<div style="clear:both;"></div>
			</div>
			<div id="datagrid1" class="nui-datagrid" style="width:100%;height:100%;"
		borderStyle="border:0" showPageSize="false" showPageIndex="false" dataField="zhmycustomers" 
		url="<%= request.getContextPath() %>/com.zhmy.xmgl.zhmycustomerbiz.queryZhmyCustomers.biz.ext">
				<div property="columns">
					<div type="checkcolumn"></div>
					<div field="customerCompanyName" width="120" headerAlign="center" allowSort="true">公司名称</div>
					<div field="customerName" width="120" headerAlign="center" allowSort="true">联系人</div>
		 		</div>
			</div>
		</div>
		<!--  look up end -->
        <script type="text/javascript">
		            nui.parse();
					//保存（编辑）数据 
		            function saveData(){
		
		                var form = new nui.Form("#dataform1");
		                form.setChanged(false);
		                //保存
		                var urlStr = "<%= request.getContextPath() %>/com.zhmy.xmgl.zhmyprojectbiz.addZhmyProject.biz.ext";
		                var pageType = nui.getbyName("pageType").getValue();//获取当前页面是编辑还是新增状态
		                //编辑
		                if(pageType=="edit"){
		                    urlStr = "<%= request.getContextPath() %>/com.zhmy.xmgl.zhmyprojectbiz.updateZhmyProject.biz.ext";
		                }
		                form.validate();
		                if(form.isValid()==false) return;
		
		                var data = form.getData(false,true);
		                var json = nui.encode(data);
						//if (data.zhmyproject.projectStartTime >= data.zhmyproject.projectEndTime) {
						//	nui.alert("开始研发时间不能小于研发结束时间");
						//}
		                $.ajax({
		                    url:urlStr,
		                    type:'POST',
		                    data:json,
		                    cache:false,
		                    contentType:'text/json',
		                    success:function(text){
		                        var returnJson = nui.decode(text);
		                        if(returnJson.exception == null){
		                        	if (returnJson.msg != null){
		                        		nui.alert(returnJson.msg);
		                        	}else{
		                        		CloseWindow("saveSuccess");
		                        	}
		                        }else{
		                            nui.alert("保存失败", "系统提示", function(action){
		                                if(action == "ok" || action == "close"){
		                                    //CloseWindow("saveFailed");
		                                }
		                                });
		                            }
		                        }
                        });
                    }

                    //页面间传输json数据
                    function setFormData(data){
                        //跨页面传递的数据对象，克隆后才可以安全使用
                        var infos = nui.clone(data);

                        //保存list页面传递过来的页面类型：add表示新增、edit表示编辑
                        nui.getbyName("pageType").setValue(infos.pageType);

                        //如果是点击编辑类型页面
                        if (infos.pageType == "edit") {
                            var json = infos.record;
                            console.log(json)
                            nui.get("lookup2").setText(json.zhmyproject.zhmyCustomer.customerName);
                            
                        	$("#version").hide();
                            var form = new nui.Form("#dataform1");//将普通form转为nui的form
                            form.setData(json);
                            form.setChanged(false);
                        }
                    }

					//将数组转化成字符串
					function test(data, field){
						var len = data.length;
						var names = "";
						for (var i = 0; i < len; i++) {
							names += data[i][field] + ",";
						}
						return names;
					}
                    //关闭窗口
                    function CloseWindow(action) {
                        if (action == "close" && form.isChanged()) {
                            if (confirm("数据被修改了，是否先保存？")) {
                                saveData();
                            }
                        }
                        if (window.CloseOwnerWindow)
                        return window.CloseOwnerWindow(action);
                        else window.close();
                    }

                    //确定保存或更新
                    function onOk() {
                        saveData();
                    }

                    //取消
                    function onCancel() {
                        CloseWindow("cancel");
                    }
                    
                    //添加选择域
                    var grid = nui.get("datagrid1");
					var keyText = nui.get("keyText");
					grid.load();
					function onSearchClick(e) { 
						grid.load({
							"criteria/_expr[1]/_likeRule" : "all",
							"criteria/_expr[1]/_op" : "like",
							"criteria/_expr[1]/customerCompanyName" : keyText.value,
							"criteria/_orderby[1]/_property" : "customerId",
							"criteria/_orderby[1]/_sort" : "asc"
						});
					}
					
					function onCloseClick(e) {
						var lookup2 = nui.get("lookup2");
						lookup2.hidePopup(); 
					}
					
					function onClearClick(e) {
						var lookup2 = nui.get("lookup2");
						$("[id^=keyText]").val("");
						lookup2.deselectAll();
					}
                </script>
            </body>
        </html>
